package com.renwei.yunlong.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.KnowSearchBean;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;
import io.github.xudaojie.qrcodelib.zxing.DensityUtils;

/**
 * 服务商 问题查询
 * <p>
 * Created by Administrator on 2017/9/13.
 */

public class KnowSearchAdapter extends BaseRecyclerViewAdapter<KnowSearchBean.RowsBean> {

    public KnowSearchAdapter(Context context) {
        super(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_work_relate, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rholder, final int position) {
        MyViewHolder holder = (MyViewHolder) rholder;
        final KnowSearchBean.RowsBean bean = getItem(position);


        holder.tvTitleContent.setText(bean.getTagContent());
        if (bean.getKnowledgeId() == 0) {
            holder.tvName.setText("/" + bean.getCategoryName());
        } else {
            holder.tvName.setText(bean.getKnowledgeId() + "/" + bean.getCategoryName());
        }
        holder.tvLeader.setVisibility(View.GONE);
        //知识状态 0:审核通过（发布） 1：待审核 2：审核不通过 3:废止
        if ("0".equals(bean.getReviewStatus())){
            holder.button.setText("发布");
            holder.button.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_3bbe7c));
        }else if ("1".equals(bean.getReviewStatus())){
            holder.button.setText("待审核");
            holder.button.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_e9981f));
        }else if ("2".equals(bean.getReviewStatus())){
            holder.button.setText("审核不通过");
            holder.button.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_e64545));
        }else if ("3".equals(bean.getReviewStatus())){
            holder.button.setText("废止");
            holder.button.setBackground(mContext.getResources().getDrawable(R.drawable.shape_card_b8bfcc));
        }

        holder.tvTime.setText(bean.getViewNum()+"");
        Drawable titleLeft = mContext.getResources().getDrawable(R.mipmap.icon_work_watch);
        titleLeft.setBounds(0, 0, DensityUtils.dp2px(mContext,13), DensityUtils.dp2px(mContext,8));
        holder.tvTime.setCompoundDrawables(titleLeft, null, null, null);
        holder.tvTime.setCompoundDrawablePadding(10);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(v, position);
            }
        });
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.tv_time)
        TextView tvTime;
        @Bind(R.id.tv_leader)
        TextView tvLeader;
        @Bind(R.id.tv_title_content)
        TextView tvTitleContent;
        @Bind(R.id.button)
        TextView button;
        @Bind(R.id.tv_name)
        TextView tvName;

        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
